﻿using Alos.IRepository;
using Alos.IService;
using PetaPoco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Alos.Entity;
using Alos.Common;

namespace Alos.Service
{
    public class SysUserInfoService : BaseService<SysUserInfo>, ISysUserInfoService
    {
        ISysUserInfoRepository SysUserInfoRepository;
        public SysUserInfoService(ISysUserInfoRepository _SysUserInfoRepository)
        {
            SysUserInfoRepository = _SysUserInfoRepository;
        }

        public SysUserInfo Login(string username, string password)
        {
            return SysUserInfoRepository.Login(username, password);
        }

        public IEnumerable<SysUserInfo> GetUserByClassId(int id, int roleid = 3)
        {
            return SysUserInfoRepository.GetUserByClassId(id, roleid);
        }
        public SysUserInfo GetCurUser(int id)
        {
            string cacheKey = "user-" + id;

            var sui = (SysUserInfo)Common.DataCache.GetCache(cacheKey);
            if (sui == null)
            {
                sui = SysUserInfoRepository.GetCurUser(id);
                Common.DataCache.SetCache(cacheKey, sui, null, TimeSpan.FromMinutes(20));
            }
            return sui;
        }
      
        public IEnumerable<SysUserInfo> GetStudentByClassId(int cid)
        {
            return SysUserInfoRepository.GetStudentByClassId(cid);
        }
    }
}
